<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="button" id="myBtn" value="Click Me">
<script>
    /*
        这个方法的任务是根据需要分别使用 DOM0 方式、 DOM2 方式或 IE 方式来添加事件处理程序
     */

    let EventUtil = {
        addHandler: function (element, type, handler) {
            if (element.addEventListener) {
                element.addEventListener(type, handler, false);
            } else if (element.attachEvent) {
                element.attachEvent("on" + type, handler);
            } else {
                element["on" + type] = handler;
            }
        },
        removeHandler: function (element, type, handler) {
            if (element.removeEventListener) {
                element.removeEventListener(type, handler, false);
            } else if (element.detachEvent) {
                element.detachEvent("on" + type, handler);
            } else {
                element["on" + type] = null;
            }
        }
    };
    
    let btn = document.getElementById('myBtn')
    let handler = () =>console.log('Clicked')
    // 添加
    EventUtil.addHandler(btn,'click',handler)
    
    // 10S后移除
    setTimeout(() =>{
        EventUtil.removeHandler(btn,'click',handler)
    },10000)


</script>
</body>
</html>